//
//  RootViewController.m
//  crazy_checkers
//
//  Created by user on 16.10.11.
//  Copyright 2011 __MyCompanyName__. All rights reserved.
//

#import "RootViewController.h"

#import <iostream>
#import "vars.h"
#import "menu.h"



@implementation RootViewControllerX

@synthesize animationTimer;
@synthesize animationInterval;


- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)didReceiveMemoryWarning
{
    // Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];
    
    // Release any cached data, images, etc that aren't in use.
}

#pragma mark - View lifecycle

- (void)viewDidLoad
{
    [super viewDidLoad];   
   
    // инициализируем глобальные переменные
	first_run = true;
	soundPresent = true;
	playerName = @"Player01";
	gameProhod = 1;// номер прохода до победы
  
    
    UIWindow *wnd = [[UIApplication sharedApplication] keyWindow] ;
    //UIView *
    //Xview=
    xGraphics3D(0,false, wnd);
    
    gameStage = new MenuStage();
  //  gameStage->viewx = Xview;
 //   gameStage->id_ = self;
	gameStage->Load();
    
	animationInterval = 1.0 / 60.0;
	[self startAnimation];    
    //[self.view addSubview:Xview];
    
    
    
    banner = [[ADBannerView alloc] initWithFrame:CGRectMake(0, 480-50, 320, 50)];
    [banner setCurrentContentSizeIdentifier:ADBannerContentSizeIdentifierPortrait];   
    banner.delegate = self;
    [self.view addSubview:banner];   
    [banner release];
   
    
}

- (void)viewDidUnload
{
    [super viewDidUnload];
    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    // Return YES for supported orientations
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}

- (void)drawView
{
	// check stage
	if(Stage::GetActive() == NULL) return;
	// update stage
	Stage::GetActive()->Update();
	// render stage
	Stage::GetActive()->Render();
}

- (void)layoutSubviews
{
    xResetGraphics();
    [self drawView];
}

- (void)startAnimation
{
    self.animationTimer = [NSTimer scheduledTimerWithTimeInterval:animationInterval target:self selector:@selector(drawView) userInfo:nil repeats:YES];
}

- (void)stopAnimation
{
    self.animationTimer = nil;
}

- (void)applicationWillResignActive:(UIApplication *)application
{
	animationInterval = 1.0 / 5.0;
    
}

- (void)applicationDidBecomeActive:(UIApplication *)application
{
	animationInterval = 1.0 / 60.0;
}


@end
